package com.jiang.专题.动态规划.Q152;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/23 13:50
 */
class Solution {
    public int maxProduct(int[] nums) {
        long max = nums[0], min = nums[0];
        int res = nums[0];
        int n = nums.length;
        for (int i = 1; i < n; i++) {
            long mx = max, mn = min;
            max = Math.max(mx * nums[i], Math.max(nums[i], mn * nums[i]));
            min = Math.min(mn * nums[i], Math.min(nums[i], mx * nums[i]));

            res = Math.max(res, (int) max);

        }
        return res;
    }
}
